<?php
if (isset($_POST["times"])){
	$arr = array(
		"time_comunication"	=>	$_POST["form_com"],
		"time_mechanic"		=>	$_POST["form_mec"],
		"time_logic"		=>	$_POST["form_log"],
		"time_physical"		=>	$_POST["form_phy"],
		"time_management"	=>	$_POST["form_man"],
		"time_creativity"	=>	$_POST["form_cre"],
		"time_leisure"		=>	$_POST["form_lei"],
		"time_research"		=>	$_POST["form_res"],
		"time_resting"		=>	$_POST["form_rest"]
		);
	$cond = array(
		"id"				=> $_SESSION["user"]["id"]
		);
	$DB->query("update", "user", $arr, $cond);
	header("Location: http://" . $_SERVER['HTTP_HOST'] . $_SESSION["path"]["header"] . "/goverment/home.php?page=free_time");
}
else{
	$userid = $_SESSION["user"]["id"];
	$arr = array(
		"time_comunication",
		"time_mechanic",
		"time_physical",
		"time_logic",
		"time_management",
		"time_creativity",
		"time_leisure",
		"time_research",
		"time_resting"
		);
	$queries = "";
	foreach ($arr as $key => $value){
		$queries .= $DB->get_query("select", "user", array($value), array("id"=>$userid)) . "; ";
	}

	$results = $DB->multiquery($queries)  or die("Error: " . $DB->error()); 
	$results = array(
		"com"=>$results[0], 
		"mec"=>$results[1], 
		"phy"=>$results[2], 
		"log"=>$results[3], 
		"man"=>$results[4], 
		"cre"=>$results[5], 
		"lei"=>$results[6], 
		"res"=>$results[7], 
		"rest"=>$results[8], 
		);
	foreach ($results as $key => $value){
		while ($row = $DB->fetch_array($value)) {
			$_SESSION["user"][$key] = $row[0];
		}
	}
	//html vars
	$com = $_SESSION["user"]["com"];
	$mec = $_SESSION["user"]["mec"];
	$phy = $_SESSION["user"]["phy"];
	$log = $_SESSION["user"]["log"];
	$man = $_SESSION["user"]["man"];
	$act = $_SESSION["user"]["act"];
	$cre = $_SESSION["user"]["cre"];
	$lei = $_SESSION["user"]["lei"];
	$res = $_SESSION["user"]["res"];
	$rest = $_SESSION["user"]["rest"];
	$user = $_SESSION["user"]["name"];
	include("/../styles/html/home/free_time.php");
}
?>